﻿using MvvmFoundation.Wpf;
using ServiceOperater.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace ServiceOperater.ViewModels
{
    public sealed class ConfigViewModel : ObservableObject
    {
        public ConfigViewModel()
        {
            ServicePath = ConfigHelper.ServiceFolderPath;
            MybatisPath = ConfigHelper.MybatisFolderPath;
            FrontPath = ConfigHelper.FrontFolderPath;
            JavaPath = ConfigHelper.JavaFolderPath;
            TextEditorPath = ConfigHelper.TextEditorPath;

            instantiateCommand();
        }

        private void instantiateCommand()
        {
            SaveConfigCommand = new RelayCommand<Object>((obj) =>
            {

            }, (obj) =>
            {
                if (FileHelper.isNotDir(ServicePath))
                {
                    return false;
                }

                if (FileHelper.isNotDir(MybatisPath))
                {
                    return false;
                }

                if (FileHelper.isNotDir(FrontPath))
                {
                    return false;
                }

                if (FileHelper.isNotDir(JavaPath))
                {
                    return false;
                }

                return true;
            });

            CloseConfigWinCommand = new RelayCommand<Object>((obj) =>
            {
                App.Messenger.NotifyColleagues(MessengerToken.WINDOW_CLOSE, this);
            }, (obj) =>
            {
                return true;
            });
        }

        #region Props
        // 
        private string servicePath = string.Empty;
        public string ServicePath
        {
            get
            {
                return servicePath;
            }
            set
            {
                if (servicePath == value)
                {
                    return;
                }

                servicePath = value;
                RaisePropertyChanged("ServicePath");
            }
        }

        private string mybatisPath = string.Empty;
        public string MybatisPath
        {
            get
            {
                return mybatisPath;
            }
            set
            {
                if (mybatisPath == value)
                {
                    return;
                }

                mybatisPath = value;
                RaisePropertyChanged("MybatisPath");
            }
        }

        private string frontPath = string.Empty;
        public string FrontPath
        {
            get
            {
                return frontPath;
            }
            set
            {
                if (frontPath == value)
                {
                    return;
                }

                frontPath = value;
                RaisePropertyChanged("FrontPath");
            }
        }

        private string javaPath = string.Empty;
        public string JavaPath
        {
            get
            {
                return javaPath;
            }
            set
            {
                if (javaPath == value)
                {
                    return;
                }

                javaPath = value;
                RaisePropertyChanged("JavaPath");
            }
        }

        private string textEditorPath = string.Empty;
        public string TextEditorPath
        {
            get
            {
                return textEditorPath;
            }
            set
            {
                if (textEditorPath == value)
                {
                    return;
                }

                textEditorPath = value;
                RaisePropertyChanged("TextEditorPath");
            }
        }

        #endregion

        #region Commands

        public RelayCommand<Object> SaveConfigCommand { get; private set; }
        public RelayCommand<Object> CloseConfigWinCommand { get; private set; }
        #endregion
    }
}
